#Inventory Tests

from django.test import TestCase
import game.inventory.models as i
from game.attributes.models import size
from game.monster.models import individual
from game.damage.models import damageType
from game.items.models import material
from game.items.models import item
from game.items.models import armor
from game.items.models import weapon

class baseInventoryTestCase(TestCase):
	fixtures = ['items/initial_data.json', 'attributes/initial_data.json',
				'combat/initial_data.json', 'inventory/initial_data.json',
				'monster/initial_data.json', 'initial_data.json']
	def setUp(self):
		self.cap = armor.objects.get(name='Cap')
		self.helmet = armor.objects.get(name='Helmet')
		self.dagger = weapon.objects.get(name='Dagger')
		self.material = material.objects.get(name='Iron')
		self.size = size.objects.get(name='Normal')
	

class instanceTestCase(baseInventoryTestCase):
	def	testInstanceDefence(self):
		"""Tests that item instances use base item and material for defence"""
		self.physicalDamage = damageType.objects.get(name='Slashing')
		self.magicalDamage = damageType.objects.get(name='Fire')
		self.helmInstance = i.itemInstance.objects.create(item = self.helmet,
			material = self.material, size = self.size)
		self.capInstance = i.itemInstance.objects.create(item = self.cap,
			material = self.material, size = self.size)
		self.assertEquals(self.helmInstance.getDefence(self.physicalDamage), 1)
		self.assertEquals(self.helmInstance.getDefence(self.magicalDamage), 0)
		self.assertEquals(self.capInstance.getDefence(self.magicalDamage), 1)
		self.assertEquals(self.capInstance.getDefence(self.physicalDamage), 0)

	def testInstanceAttack(self):
		"""Tests that item instances use base item and material for attack"""
		self.daggerInstance = i.itemInstance.objects.create(item = self.dagger,
			material = self.material, size = self.size)
		self.damage = self.daggerInstance.getAttack()
		self.assertEquals(self.damage.power, 1)
		self.material.damageModifierCollection.basePhysicalAttack=1
		self.material.damageModifierCollection.save()
		self.damage  = self.daggerInstance.getAttack()
		self.assertEquals(self.damage.power, 2)

class equipTestCase(baseInventoryTestCase):
	def testEquip(self):
		self.helmetInstance=i.itemInstance.objects.create(item = self.helmet,
			material = self.material, size=self.size)
		self.Ind = individual.objects.get(id=1)
		#nothing should be equiped
		self.assertEquals(len(i.equipedItems.objects.slotsUsed(self.Ind)),0)
		#equip the helmet
		self.assertEquals(i.equipedItems.objects.equipItem(self.Ind, self.helmetInstance),True)
		#check helmet is equiped
		self.assertEquals(len(i.equipedItems.objects.slotsUsed(self.Ind)),1)
		#unequip the helmet
		self.assertEquals(i.equipedItems.objects.unEquipItem(self.Ind, self.helmetInstance),True)
		#nothing should be equiped
		self.assertEquals(len(i.equipedItems.objects.slotsUsed(self.Ind)),0)
		#assert unequipin or equiping a bad item fails
		self.assertEquals(i.equipedItems.objects.unEquipItem('pie', 'pie'),False)
		self.assertEquals(i.equipedItems.objects.equipItem('pie', 'pie'),False)
